#!/usr/bin/env python

import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import datetime
from django.utils import simplejson
import cgi

from model import Course
from model import Lecturer


class MyHandler(webapp.RequestHandler):
    def get(self):
        form = cgi.FieldStorage()
        courseName = form.getvalue("name")

        lecturer = None
        # For ease of debugging, remove when done!
        if form.getvalue("lecturer") != None:
            lecturer = Lecturer.get(form.getvalue("lecturer"))
        
        course = Course(name = courseName, lecturer = lecturer)
        course.put()

        self.response.out.write("success")

def main():
    app = webapp.WSGIApplication([
        (r'.*', MyHandler)], debug=True)
    wsgiref.handlers.CGIHandler().run(app)

if __name__ == "__main__":
    main()